<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>

        const users = [
            { name: 'jack', age: 20 },
            { name: 'lili', age: 19 },
            { name: 'lucy', age: 21 },
            { name: 'wukong', age: 22 },
            { name: 'tom', age: 18 },
        ];

        // 找对象中可排序字段
        users.sort((a, b) => {
            if (a.age < b.age) {
                return 1
            } else {
                return -1
            }
        });

        console.log(users);

    </script>
</body>

</html>